import Vue from 'vue'
import App from './App.vue'
import initWebsocket, { bindSocketMessage } from './utils/socketMessage'
import Models from './models'

Function.prototype.IsFunction = true
Array.prototype.IsArray = true
Date.prototype.IsDate = true
Number.prototype.IsNumber = true
Boolean.prototype.IsBoolean = true

Vue.config.productionTip = false

function initVue(connectionId) {
  Vue.mixin({
    data() {
      return {
        connectionId,
      }
    },
  })
  new Vue({
    render: (h) => h(App),
  }).$mount('#app')
}

initWebsocket(initVue)
bindSocketMessage('globalUpdateEvents', {
  updateData(param) {
    const model = Models[param.name]
    if (!model) {
      return
    }
    model.push(param.data)
  }
})